Basic Model Loading
create_model()
The core function for creating CLIP models with flexible configuration options.str
required
Model architecture name (e.g., ‘ViT-B-32’, ‘RN50’) or schema-prefixed path:
- Built-in:
'ViT-B-32' - HuggingFace Hub:
'hf-hub:org/repo' - Local directory:
'local-dir:/path/to/model'
str
Pretrained weights source. Can be:
- Tag name (e.g., ‘openai’, ‘laion2b_s34b_b79k’)
- Local file path (e.g., ‘/path/to/weights.pt’)
- Ignored if model_name uses schema prefix
str | torch.device
default:"cpu"
Device to load model on (‘cpu’, ‘cuda’, etc.)
str
default:"fp32"
Model precision: ‘fp32’, ‘fp16’, ‘bf16’, ‘pure_fp16’, ‘pure_bf16’
bool
default:"False"
Whether to JIT compile the model
int | Tuple[int, int]
Override default image size for the model
str
Directory for caching downloaded weights
Loading Schemas
HuggingFace Hub
Load models directly from HuggingFace Hub using thehf-hub: schema:
- Downloads
open_clip_config.jsonfrom the repo - Looks for weights files (
.safetensors,.bin,.pth) - Merges preprocessing configuration
Local Directory
Load from a local directory containing model config and weights:Local directory must contain:
open_clip_config.jsonwith model configuration- Weight file (searched in order):
open_clip_model.safetensors,pytorch_model.bin,model.pth, etc.
Local File Path
Load weights from a specific file:Advanced Loading Options
Tower-Specific Weights
Load separate weights for image and text towers:bool
default:"False"
Load default pretrained weights for image tower (timm models)
bool
default:"True"
Load default pretrained weights for text tower (HuggingFace models)
str
Path to custom image tower weights (loaded after full model)
str
Path to custom text tower weights (loaded after full model)
Custom Model Configuration
Override model architecture parameters:create_model_and_transforms()
Convenience function that returns model with preprocessing transforms:(model, train_transform, val_transform). The transforms handle:
- Image resizing and cropping
- Normalization with correct mean/std
- Data augmentation (training only)
create_model_from_pretrained()
Strictly requires pretrained weights (raises error if weights can’t be loaded):bool
default:"True"
Whether to return preprocessing transform. If False, returns only model.
Listing Available Models
Weight Loading Options
bool
default:"True"
Whether to load the resolved pretrained weights. Set to False for random initialization.
bool
default:"False"
Raise error if pretrained weights cannot be loaded
bool
default:"True"
Use
weights_only=True for torch.load (safer, prevents arbitrary code execution)